simplified agent to retrieve data only

Judy Ngai 9 years ago
parent
commit
0ae228b0ec
1 changed files with 6 additions and 19 deletions
  1. 6 19
      app/models/agents/aftership_agent.rb

+ 6 - 19
app/models/agents/aftership_agent.rb

@@ -119,21 +119,13 @@ module Agents
119 119
     end
120 120
 
121 121
     def single_tracking_request?
122
-      boolify(interpolated[:single_tracking_request]) != "false"
123
-    end
124
-
125
-    def last_checkpoint?
126
-      boolify(interpolated[:last_checkpoint]) != "false"
122
+      interpolated[:single_tracking_request] != "false"
127 123
     end
128 124
 
129 125
     def uri
130 126
       uri = URI.parse API_URL
131
-      if options['get'] && single_tracking_request?
127
+      if single_tracking_request?
132 128
         uri.query = interpolated['get']+ '/' + interpolated['slug'] + '/' + interpolated['tracking_number'] if uri.query.nil? 
133
-      elsif options['get'] && last_checkpoint?
134
-        uri.query = interpolated['get'] + '/' + interpolated['slug'] + '/' + interpolated['tracking_number'] if uri.query.nil?
135
-      elsif options['delete']
136
-        uri.query = interpolated['delete'] + interpolated['slug'] + '/' + interpolated['tracking_number'] if uri.query.nil?
137 129
       else
138 130
         uri.query = interpolated['get'] if uri.query.nil? 
139 131
       end
@@ -141,13 +133,12 @@ module Agents
141 133
     end
142 134
 
143 135
     def working?
144
-      (events_count.present? && events_count > 0)
136
+      true
145 137
     end
146 138
 
147 139
     def validate_options
148 140
       errors.add(:base, "You need to specify a api key") unless options['api_key'].present?
149 141
       errors.add(:base, "Content-Type must be set to application/json") unless options['Content_Type'].present? && options['Content_Type'] == 'application/json'
150
-      errors.add(:base, "You need to specify a certain request") unless options['get'].present? || options['delete'].present?
151 142
     end
152 143
 
153 144
     def request_options
@@ -155,13 +146,9 @@ module Agents
155 146
     end
156 147
 
157 148
     def check
158
-      if options['get'] 
159
-        response = HTTParty.get(uri, request_options)
160
-        events = JSON.parse response.body
161
-        create_event :payload => events
162
-      elsif options['delete']
163
-        response = HTTParty.delete(uri, request_options)
164
-      end
149
+      response = HTTParty.get(uri, request_options)
150
+      events = JSON.parse response.body
151
+      create_event :payload => events
165 152
     end
166 153
   end
167 154
 end